// common/models/auth/token_model.dart

/// 令牌模型
/// 基于hello-auth-api.md定义的令牌数据结构
class TokenModel {
  /// 访问令牌
  final String accessToken;
  
  /// 刷新令牌
  final String refreshToken;
  
  /// 访问令牌过期时间（分钟）
  final int expiresIn;
  
  /// 刷新令牌过期时间（分钟）
  final int refreshExpiresIn;
  
  const TokenModel({
    required this.accessToken,
    required this.refreshToken,
    required this.expiresIn,
    required this.refreshExpiresIn,
  });
  
  /// 从JSON创建实例
  factory TokenModel.fromJson(Map<String, dynamic> json) {
    return TokenModel(
      accessToken: json['access_token'] as String,
      refreshToken: json['refresh_token'] as String,
      expiresIn: json['expires_in'] as int,
      refreshExpiresIn: json['refresh_expires_in'] as int,
    );
  }
  
  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'access_token': accessToken,
      'refresh_token': refreshToken,
      'expires_in': expiresIn,
      'refresh_expires_in': refreshExpiresIn,
    };
  }
  
  @override
  String toString() {
    return 'TokenModel(accessToken: [HIDDEN], refreshToken: [HIDDEN], expiresIn: $expiresIn, refreshExpiresIn: $refreshExpiresIn)';
  }
  
  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is TokenModel &&
        other.accessToken == accessToken &&
        other.refreshToken == refreshToken &&
        other.expiresIn == expiresIn &&
        other.refreshExpiresIn == refreshExpiresIn;
  }
  
  @override
  int get hashCode {
    return accessToken.hashCode ^
        refreshToken.hashCode ^
        expiresIn.hashCode ^
        refreshExpiresIn.hashCode;
  }
}